package com.dhcc.wb.yijian;

import com.dhcc.common.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.json.JSONArray;
import org.json.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @author wanggx
 * @date 2019/12/3 17:50
 */
public class WxIdeaAction extends ActionSupport {
    private static Logger logger = Logger.getLogger(WxIdeaAction.class);
    //增加意见
    public void addWxIdeaAction() throws IOException {
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
        PrintWriter out = response.getWriter();
        String name = request.getParameter("name");
        String bumeng = request.getParameter("company_name");
        String neirong = request.getParameter("content");
        SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        Date now=new Date();
        String TimeStamp=myFmt.format(now).toString();
        System.out.println(myFmt.format(now));
        WxIdeaDao dao = new WxIdeaDao();
        int result = 0;
        if (!StringUtil.isNullOrEmpty(name)&&!StringUtil.isNullOrEmpty(bumeng)&&!StringUtil.isNullOrEmpty(neirong)){
            result = dao.addWxIdea(UUID.randomUUID().toString(),name,bumeng,TimeStamp,neirong,null,null);
        }
        logger.info("增加意见的返回结果"+result);
        JSONObject json = new JSONObject();
        JSONArray jsons = new JSONArray();
        if (result>0){
            json.put("status","success");
        }else {
            json.put("status","failed");
        }
        //jsons.put(json);
        out.println(json.toString());
    }

}
